import os
import configparser
import pymysql

# 获取当前脚本所在目录的绝对路径
script_dir = os.path.dirname(os.path.abspath(__file__))

config = configparser.ConfigParser()
config.read(os.path.join(script_dir, 'config.ini'))

url_section = config['MYSQL']
mysql_host = url_section['mysql_host']
mysql_port = url_section['mysql_port']
mysql_user = url_section['mysql_user']
mysql_password = url_section['mysql_password']
mysql_database = url_section['mysql_database']
default_area_code = url_section['default_area_code']

# 连接到数据库
conn = pymysql.connect(host=mysql_host,
                       port=int(mysql_port),
                       user=mysql_user,
                       password=mysql_password,
                       database=mysql_database,
                       cursorclass=pymysql.cursors.DictCursor  # 使用字典游标
                       )
cursor = conn.cursor()

topic: {

}


##获取主题
def get_topic():
    # 查询数据
    query = "SELECT * FROM public_opinion_topic where guizhou = 1"
    cursor.execute(query)

    # 获取所有结果
    result = cursor.fetchone()

    global topic  # 声明使用全局变量
    topic = result

    print("topic:", topic)



# 主程序
if __name__ == "__main__":
    citys = ['贵阳市', '遵义市', '六盘水市', '安顺市', '毕节市', '铜仁市', '黔东南苗族侗族自治州', '黔南布依族苗族自治州', '黔西南布依族苗族自治州']
    get_topic()
